//启动

package main

import (
	"flag"
	"fmt"
	"gitee.com/zxh/easy-chat/apps/im/ws/internal/config"
	"gitee.com/zxh/easy-chat/apps/im/ws/internal/handler"
	"gitee.com/zxh/easy-chat/apps/im/ws/internal/svc"
	"gitee.com/zxh/easy-chat/apps/im/ws/websocket"
	"github.com/zeromicro/go-zero/core/conf"
)

// 加载配置
var configFile = flag.String("f", "etc/dev/im.yaml", "the config file")

func main() {
	flag.Parse()

	//加载配置
	var c config.Config
	conf.MustLoad(*configFile, &c)

	//SetUp()，启动go-zero中日志、监听等功能
	if err := c.SetUp(); err != nil {
		panic(err)
	}

	//初始化ServiceContext
	ctx := svc.NewServiceContext(c)

	//创建websocket服务对象
	srv := websocket.NewServer(
		c.ListenOn,
		websocket.WithServerAuthentication(handler.NewJwtAuth(ctx)),
		//websocket.WithServerMaxConnectionIdle(10*time.Second),
	)
	defer srv.Stop()

	//注册路由
	handler.RegisterHandlers(srv, ctx)

	//启动服务
	fmt.Println("start websocket server at ", c.ListenOn, " ......")
	srv.Start()
}
